<template>
	<view class="deposit">
		<view class="deposit-title">
			<image class="img" :src="imgUrl2" ></image>
		</view>
		<view class="deposit-main">
			<uni-card class="u-card" :is-shadow="false" :border="false" :margin="0" :spacing="'0 20rpx'" :padding="0">
				<view class="number">
					<view class="sum">
						<text class="sum-text">￥</text><text class="sum-text sum-sum">{{bond || '0.00'}}</text>
					</view>
					<text class="number-text">保证金金额</text>
				</view>
				<view class="card-but">
					<button v-if="bond <= 0" class="but but1" plain @click="payGo('pay')">缴纳保证金</button>
					<button v-else class="but" plain @click="rebate('rebate')">申请退款</button>
				</view>
			</uni-card>
			<uni-card class="u-card1" :is-shadow="false" :border="false" :margin="0" :spacing="'0 40rpx'" :padding="0">
				<view class="card1-title">
					<text class="title-text">保证金规则</text>
				</view>
				<u-parse :content="data" ></u-parse>
			</uni-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl:`${getApp().globalData.imgScr}jd/shimingrenzheng.png`,
				imgUrl2:`${getApp().globalData.imgScr}jd/baozhengjing.png`,
				url: '/hotelAdmin/my',
				url1: '/hotelAdmin/my/common',
				data:'加载中...', // 保证金规则
				price:0, // 保证金金额
				bond:0,
				hotel_id: ''
			}	
		},
		onLoad(options) {
			this.hotel_id = options.hotel_id
			this.getClick()
		},
		onShow() {
		},
		methods:{
			/**
			 * 立即充值按钮
			 */
			payGo:async function() {
				let _this = this
					try {
						uni.showLoading({ title: '充值中....' })
							let res = await this.$http.post('/index/Hotelrecharge/bond_order',{hotel_id:_this.hotel_id})
							console.log('支付成功',res)
							let rep = await this.$http.post('/index/Hotelrecharge/bond_order_pay',{order_id:res,openid:uni.getStorageSync('hotelData').openid})
							console.log('支付成功1',rep)
							let pay = await uni.requestPayment({
							    provider: 'wxpay',
							    timeStamp: rep.timeStamp,
							    nonceStr: rep.nonceStr,
							    package: rep.package,
							    signType: rep.signType,
							    paySign: rep.paySign,
							});
							console.log('支付成功2',pay)
							if(pay[0] && pay[0].errMsg == "requestPayment:fail cancel") uni.showToast({
								title: '取消支付',
								icon: 'none',
							});
							else if(pay[1] && pay[1].errMsg == "requestPayment:ok") uni.showToast({
								title: '支付成功',
								icon: 'none',
								success() {
									_this.getClick()
								}
							});
							uni.hideLoading()
					}catch (e) {
						uni.hideLoading()
						uni.showToast({
							title:e.errMsg,
							icon:"none"
						})
					}
			},
		/**
		 * 申请退款按钮
		 */
		rebate() {
			uni.navigateTo({
				url: '/hotelAdmin/my/common/rebate/rebate?id=' + 2 +'&price=' + this.bond + "&hotel_id=" + this.hotel_id
				// url: `${this.url1}/${path}/${path}?id=2&price=${this.bond}`,
			});
		},
		/**
		 * 请求数据
		 */
		async getClick() {
			let _this = this
			try{
				let res = await this.$http.post('/index/Hotelpersonal/hotelinfo',{hotel_id: _this.hotel_id})
				this.bond = res.bond
				let rep = await this.$http.post('/index/Communal/config_data',{
					config_id:6,
					hotel_id: _this.hotel_id
					})
				// this.data = rep.bond_role.value.replace(/src="\//g, 'class="img-14" src="https://www.zhuoxianrenli.cn/' ) || '暂无数据！';
				this.data = rep.bond_role.value.replace(/src="\//g, `class="img-14" src="${getApp().globalData.url}` ) || '暂无数据！';
				this.price = rep.bond_price.value
			}catch(e){
				uni.showToast({
					title: e.errMsg,
					icon:"none"
				})
			}
			
		},
		},
	}
</script>

<style lang="scss">
.deposit {
	position: relative;
	height: 100vh;
	.deposit-title {
		width: 100%;
		height: 406rpx;
		overflow: hidden;
		.img {
			width: 100%;
			height: 100%;
		}
	}
	.deposit-main {
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 100%;
		height: calc(100vh - 366rpx);
		border-radius:40rpx;
		z-index: 9999;
		margin-top: -40rpx;
		overflow: hidden;
		.u-card {
			flex: 2;
			margin-bottom: 20rpx;
			.number {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin: 40rpx 0;
				.sum {
					.sum-text {
						font-size: 32rpx;
						font-weight: 600;
						color: #333333;
					}
					.sum-sum {
						font-size: 40rpx;
					}
				}
				.number-text {
					font-size: 24rpx;
					font-weight: 500;
					color: #999999;
				}
			}
			.card-but {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.but {
					width: 530rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: rgba($color: #000000, $alpha: 0.7);
					background: #F2F2F2;
					border-radius: 34rpx;
					line-height: 68rpx;
					border: 0;
					margin: 0 20rpx;
					margin-bottom: 20rpx;
				}
				.but1 {
					color: #FFFFFF;
					background: linear-gradient(-90deg, #8dc9f1, #d8eefc);
				}
			}
		}
		.u-card1 {
			flex: 3;
			overflow: hidden;
			.img-14 {
				width: 100%!important;
			}
			.card1-title {
				margin: 20rpx 0;
				.title-text {
					font-size: 34rpx;
					font-weight: 600;
					color: #000000;
				}
			}
			.uni-col-22 {
				margin-left: 10rpx;
				margin-bottom: 10rpx;
			}
			.img {
				width: 24rpx;
				height: 24rpx;
			}
			.col-text {
				font-size: 28rpx;
				font-weight: 500;
				color: #333333;
			}
			.col-text1 {
				font-size: 24rpx;
				font-weight: 500;
				color: rgba($color: #000000, $alpha: 0.7);
			}
		}
		.uni-card {
			height: 100%;
			overflow: auto;
		}
		
	}
}
</style>